Today, a data unit (“packet”) can traverse a number of interconnected networks to reach a destination. Typically, a network device such as a router routes and forwards packets across network boundaries using an optimal path. The router can use a number of protocols to route and forward the packets. A packet typically includes protocol headers to indicate the protocol being used for the packet and a payload section storing data. The router thus performs two basic types of operations such as parsing a packet of protocol headers to extract data within the packet and encapsulating data with protocol headers to form a packet for delivery.
A prior parsing and encapsulating technique is by hard-wired circuitry. That is, circuitry is hard-wired to parse specific packets or to encapsulate data with specific protocol headers for varying types of packets. A disadvantage, however, of using hard-wired circuitry is that it is not programmable. In particular, hard-wired circuitry is not flexible or adaptable to support packets for new types of protocols. For example, if a new protocol is being used for routing a packet, the packet will include a new type of protocol header. Consequently, if the hard-wired circuitry is not designed to handle the new type of protocol header, new hard-wired circuitry must be designed and implemented to support such a new protocol.
Another prior parsing and encapsulating technique is using a network processor that must access external memory to process code or instructions for performing parsing and encapsulating functions. A disadvantage of this technique is high latency due to the network processor spending time to accessing external memory. Such a high latency can cause parsing of a packet and encapsulating data to form a packet to be slow for a router. Consequently, because the parsing and encapsulating functions must be performed at very high speeds in order to keep up with the high data rates supported by a router, such a technique is not adequate to perform parsing and encapsulating at high data rates.
Another disadvantage of this technique is that a separate program is required for each type of variation a packet may have based on the number of combinations of protocols that may be supported for a packet. The number of programs can thus be very large thereby placing a heavy burden on memory resources. Consequently, the prior technique of a network processor accessing external memory to process code or instructions for parsing a packet or encapsulating data to form a packet is inefficient for a router.